package blue.squares;

import android.graphics.Color;
import android.os.Parcel;
import android.os.Parcelable;

/**
 *
 * @author Luisa Lu
 */
public class Player implements Parcelable{
    // ------------------------------------------------------------------------
    // Fields.
    // ------------------------------------------------------------------------

    // Index of the player.  One of [0,N-1] for N players.
    int _id;
    // This player's color.
    int _color;
    // This player's current point total.
    int _score;
    // The player's controller.  For local human players this is null.
    Strategy _strategy;

    // ------------------------------------------------------------------------
    // Implementation.
    // ------------------------------------------------------------------------

    public Player(int id, int color) {
        _id = id;
        _color = color;
        _score = 0;
    }

    public int getId() {
        return _id;
    }

    public int getColor() {
        return _color;
    }

    public int getScore() {
        return _score;
    }

    public void setStrategy(Strategy strategy) {
        _strategy = strategy;
    }

    public void incrementScore(int points) {
        _score += points;
    }

    public boolean isLocalHuman() {
        return _strategy == null;
    }

    public Strategy getStrategy() {
        return _strategy;
    }

    @Override
    public String toString(){
        return "Color=("+ Color.red(_color)+","+Color.green(_color)+","+Color.blue(_color)+") " +
                "Score="+_score+" Strategy="+_strategy;
    }

    // ------------------------------------------------------------------------
    // Parcelable implementation.
    // ------------------------------------------------------------------------
    
    public Player(Parcel in){
        _id = in.readInt();
        _color = in.readInt();
        _score = in.readInt();
        // TODO: read in strategy                
    }

    public int describeContents() { // TODO: what the heck is this for
        return 0;
    }

    public void writeToParcel(Parcel out, int flag) {
        out.writeInt(_id);
        out.writeInt(_color);
        out.writeInt(_score);
        // TODO: write out strategy
    }
    
    public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
        public Player createFromParcel(Parcel in) { 
            return new Player(in);
        }

        public Player[] newArray(int size) {
            return new Player[size];
        }
    };

}
